package cn.yzx.pethome.system.login.controller;


import cn.yzx.pethome.constants.BaseConstants;
import cn.yzx.pethome.system.logininfo.domain.Logininfo;
import cn.yzx.pethome.system.logininfo.service.ILogininfoService;
import cn.yzx.pethome.system.user.domain.User;
import cn.yzx.pethome.system.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("act")
public class ActEmailController {
    @Autowired
    private IUserService userService;
    @Autowired
    private ILogininfoService logininfoService;
    @GetMapping("/email/{id}")
    public String actEmail(@PathVariable Long id){
        try {
            User user = userService.findOne(id);
            user.setState(BaseConstants.User.STATE_NORMAL);
            userService.update(user);
            Logininfo logininfo = logininfoService.findOne(user.getLogininfoId());
            logininfo.setDisable(BaseConstants.Logininfo.DISABLE_1);
            logininfoService.update(logininfo);
            return "激活成功";
        } catch (Exception e) {
            e.printStackTrace();
            return "网络异常请联系管理员";
        }
    }
}
